<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Kruskal's algorithm</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Kruskal's_algorithm"> <link href="./mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.math.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Kruskal_s_algorithm rootpage-Kruskal_s_algorithm skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">Kruskal's algorithm</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">
<style data-mw-deduplicate="TemplateStyles:r1236090951">
/* start https://en.wikipedia.org/ */
.mw-parser-output .hatnote{font-style:italic}.mw-parser-output div.hatnote{padding-left:1.6em;margin-bottom:0.5em}.mw-parser-output .hatnote i{font-style:normal}.mw-parser-output .hatnote+link+.hatnote{margin-top:-0.5em}@media print{body.ns-0 .mw-parser-output .hatnote{display:none!important}}
/* end https://en.wikipedia.org/ */
</style><div role="note" class="hatnote navigation-not-searchable">Not to be confused with <a href="Kruskal's_principle" class="mw-redirect" title="Kruskal's principle">Kruskal's principle</a>.</div>
<style data-mw-deduplicate="TemplateStyles:r1295905060">
/* start https://en.wikipedia.org/ */
.mw-parser-output .infobox-subbox{padding:0;border:none;margin:-3px;width:auto;min-width:100%;font-size:100%;clear:none;float:none;background-color:transparent}.mw-parser-output .infobox-3cols-child{margin:auto}.mw-parser-output .infobox .navbar{font-size:100%}@media screen{html.skin-theme-clientpref-night .mw-parser-output .infobox-full-data:not(.notheme)>div:not(.notheme)[style]{background:#1f1f23!important;color:#f8f9fa}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .infobox-full-data:not(.notheme)>div:not(.notheme)[style]{background:#1f1f23!important;color:#f8f9fa}}@media(min-width:640px){body.skin--responsive .mw-parser-output .infobox-table{display:table!important}body.skin--responsive .mw-parser-output .infobox-table>caption{display:table-caption!important}body.skin--responsive .mw-parser-output .infobox-table>tbody{display:table-row-group}body.skin--responsive .mw-parser-output .infobox-table th,body.skin--responsive .mw-parser-output .infobox-table td{padding-left:inherit;padding-right:inherit}}
/* end https://en.wikipedia.org/ */
</style><table class="infobox"><caption class="infobox-title">Kruskal's algorithm</caption><tbody><tr><td colspan="2" class="infobox-image"><div class="infobox-caption">Animation of Kruskal's algorithm on a <a href="Complete_graph" title="Complete graph">complete graph</a> with weights based on Euclidean distance</div></td></tr><tr><th scope="row" class="infobox-label">Class</th><td class="infobox-data"><a href="Minimum_spanning_tree" title="Minimum spanning tree">Minimum spanning tree algorithm</a></td></tr><tr><th scope="row" class="infobox-label">Data structure</th><td class="infobox-data"><a href="Graph_(abstract_data_type)" title="Graph (abstract data type)">Graph</a></td></tr><tr><th scope="row" class="infobox-label"><a href="Best%2C_worst_and_average_case" title="Best, worst and average case">Worst-case</a> <a href="Time_complexity" title="Time complexity">performance</a></th><td class="infobox-data"><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle O(|E|\log |V|)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>O</mi>
<mo stretchy="false">(</mo>
<mrow class="MJX-TeXAtom-ORD">
<mo stretchy="false">|</mo>
</mrow>
<mi>E</mi>
<mrow class="MJX-TeXAtom-ORD">
<mo stretchy="false">|</mo>
</mrow>
<mi>log</mi>
<mo><!-- --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mo stretchy="false">|</mo>
</mrow>
<mi>V</mi>
<mrow class="MJX-TeXAtom-ORD">
<mo stretchy="false">|</mo>
</mrow>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle O(|E|\log |V|)}</annotation>
</semantics>
</math></span><img src="./22c52b62d653c3f6686207ef2b6b5907dcd8b5ac.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:13.479ex; height:2.843ex;" alt="{\displaystyle O(|E|\log |V|)}" loading="lazy"></span></td></tr></tbody></table>
<p><b>Kruskal's algorithm</b><sup id="cite_ref-1" class="reference"><a href="#cite_note-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> finds a <a href="Minimum_spanning_tree" title="Minimum spanning tree">minimum spanning forest</a> of an undirected <a href="Weighted_graph" class="mw-redirect" title="Weighted graph">edge-weighted graph</a>. If the graph is <a href="Connectivity_(graph_theory)" title="Connectivity (graph theory)">connected</a>, it finds a <a href="Minimum_spanning_tree" title="Minimum spanning tree">minimum spanning tree</a>. It is a <a href="Greedy_algorithm" title="Greedy algorithm">greedy algorithm</a> that in each step adds to the forest the lowest-weight edge that will not form a <a href="Cycle_(graph_theory)" title="Cycle (graph theory)">cycle</a>.<sup id="cite_ref-:0_2-0" class="reference"><a href="#cite_note-:0-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup> The key steps of the algorithm are <a href="Sorting" title="Sorting">sorting</a> and the use of a <a href="Disjoint-set_data_structure" title="Disjoint-set data structure">disjoint-set data structure</a> to detect cycles. Its running time is dominated by the time to sort all of the graph edges by their weight.
</p><p>A minimum spanning tree of a connected weighted graph is a connected subgraph, without cycles, for which the sum of the weights of all the edges in the subgraph is minimal. For a disconnected graph, a minimum spanning forest is composed of a minimum spanning tree for each <a href="Connected_component_(graph_theory)" class="mw-redirect" title="Connected component (graph theory)">connected component</a>.
</p><p>This algorithm was first published by <a href="Joseph_Kruskal" title="Joseph Kruskal">Joseph Kruskal</a> in 1956,<sup id="cite_ref-3" class="reference"><a href="#cite_note-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup> and was rediscovered soon afterward by <a href="#CITEREFLobermanWeinberger1957">Loberman & Weinberger (1957)</a>.<sup id="cite_ref-4" class="reference"><a href="#cite_note-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup> Other algorithms for this problem include <a href="Prim's_algorithm" title="Prim's algorithm">Prim's algorithm</a>, <a href="Bor%C5%AFvka's_algorithm" title="Borůvka's algorithm">Borůvka's algorithm</a>, and the <a href="Reverse-delete_algorithm" title="Reverse-delete algorithm">reverse-delete algorithm</a>.
</p>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="Algorithm">Algorithm</h2></div>
<p>The algorithm performs the following steps:
</p>
<ul><li>Create a forest (a set of trees) initially consisting of a separate single-vertex tree for each vertex in the input graph.</li>
<li>Sort the graph edges by weight.</li>
<li>Loop through the edges of the graph, in ascending sorted order by their weight. For each edge:
<ul><li>Test whether adding the edge to the current forest would create a cycle.</li>
<li>If not, add the edge to the forest, combining two trees into a single tree.</li></ul></li></ul>
<p>At the termination of the algorithm, the forest forms a minimum spanning forest of the graph. If the graph is connected, the forest has a single component and forms a minimum spanning tree.
</p>
<div class="mw-heading mw-heading2"><h2 id="Pseudocode">Pseudocode</h2></div>
<p>The following code is implemented with a <a href="Disjoint-set_data_structure" title="Disjoint-set data structure">disjoint-set data structure</a>. It represents the forest <i>F</i> as a set of undirected edges, and uses the disjoint-set data structure to efficiently determine whether two vertices are part of the same tree.
</p>
<pre><b>function</b> Kruskal(<i>Graph G</i>) <b>is</b>
F:= ∅
<b>for each</b> v <b>in</b> G.Vertices <b>do</b>
MAKE-SET(v)
<b>for each</b> {u, v} <b>in</b> G.Edges ordered by increasing weight({u, v}) <b>do</b>
<b>if</b> FIND-SET(u) ≠ FIND-SET(v) <b>then</b>
F := F ∪ { {u, v} }
UNION(FIND-SET(u), FIND-SET(v))
<b>return</b> F
</pre>
<div class="mw-heading mw-heading2"><h2 id="Complexity">Complexity</h2></div>
<p>For a graph with <span class="texhtml mvar" style="font-style:italic;">E</span> edges and <span class="texhtml mvar" style="font-style:italic;">V</span> vertices, Kruskal's algorithm can be shown to run in time <span class="texhtml"><i>O</i>(<i>E</i> log <i>E</i>)</span> time, with simple data structures. This time bound is often written instead as <span class="texhtml"><i>O</i>(<i>E</i> log <i>V</i>)</span>, which is equivalent for graphs with no isolated vertices, because for these graphs <span class="texhtml"><i>V</i>/2 ≤ <i>E</i> < <i>V</i><sup>2</sup></span> and the logarithms of <span class="texhtml mvar" style="font-style:italic;">V</span> and <span class="texhtml mvar" style="font-style:italic;">E</span> are again within a constant factor of each other.
</p><p>To achieve this bound, first sort the edges by weight using a <a href="Comparison_sort" title="Comparison sort">comparison sort</a> in <span class="texhtml"><i>O</i>(<i>E</i> log <i>E</i>)</span> time. Once sorted, it is possible to loop through the edges in sorted order in constant time per edge. Next, use a <a href="Disjoint-set_data_structure" title="Disjoint-set data structure">disjoint-set data structure</a>, with a set of vertices for each component, to keep track of which vertices are in which components. Creating this structure, with a separate set for each vertex, takes <span class="texhtml mvar" style="font-style:italic;">V</span> operations and <span class="texhtml"><i>O</i>(<i>V</i>)</span> time. The final iteration through all edges performs two find operations and possibly one union operation per edge. These operations take <a href="Amortized_time" class="mw-redirect" title="Amortized time">amortized time</a> <span class="texhtml"><i>O</i>(<i>α</i>(<i>V</i>))</span> time per operation, giving worst-case total time <span class="texhtml"><i>O</i>(<i>E</i> <i>α</i>(<i>V</i>))</span> for this loop, where <span class="texhtml mvar" style="font-style:italic;">α</span> is the extremely slowly growing <a href="Inverse_Ackermann_function" class="mw-redirect" title="Inverse Ackermann function">inverse Ackermann function</a>. This part of the time bound is much smaller than the time for the sorting step, so the total time for the algorithm can be simplified to the time for the sorting step.
</p><p>In cases where the edges are already sorted, or where they have small enough integer weight to allow <a href="Integer_sorting" title="Integer sorting">integer sorting</a> algorithms such as <a href="Counting_sort" title="Counting sort">counting sort</a> or <a href="Radix_sort" title="Radix sort">radix sort</a> to sort them in linear time, the disjoint set operations are the slowest remaining part of the algorithm and the total time is <span class="texhtml"><i>O</i>(<i>E</i> <i>α</i>(<i>V</i>))</span>.
</p>
<div class="mw-heading mw-heading2"><h2 id="Example">Example</h2></div>
<table class="wikitable">
<tbody><tr>
<th>Image</th>
<th>Description
</th></tr>
<tr>
<td><span typeof="mw:File"></span>
</td>
<td><b>AD</b> and <b>CE</b> are the shortest edges, with length 5, and <b>AD</b> has been <a href="Arbitrary" class="mw-redirect" title="Arbitrary">arbitrarily</a> chosen, so it is highlighted.
</td></tr>
<tr>
<td><span typeof="mw:File"></span>
</td>
<td><b>CE</b> is now the shortest edge that does not form a cycle, with length 5, so it is highlighted as the second edge.
</td></tr>
<tr>
<td><span typeof="mw:File"></span>
</td>
<td>The next edge, <b>DF</b> with length 6, is highlighted using much the same method.
</td></tr>
<tr>
<td><span typeof="mw:File"></span>
</td>
<td>The next-shortest edges are <b>AB</b> and <b>BE</b>, both with length 7. <b>AB</b> is chosen arbitrarily, and is highlighted. The edge <b>BD</b> has been highlighted in red, because there already exists a path (in green) between <b>B</b> and <b>D</b>, so it would form a cycle (<b>ABD</b>) if it were chosen.
</td></tr>
<tr>
<td><span typeof="mw:File"></span>
</td>
<td>The process continues to highlight the next-smallest edge, <b>BE</b> with length 7. Many more edges are highlighted in red at this stage: <b>BC</b> because it would form the loop <b>BCE</b>, <b>DE</b> because it would form the loop <b>DEBA</b>, and <b>FE</b> because it would form <b>FEBAD</b>.
</td></tr>
<tr>
<td><span typeof="mw:File"></span>
</td>
<td>Finally, the process finishes with the edge <b>EG</b> of length 9, and the minimum spanning tree is found.
</td></tr></tbody></table>
<div class="mw-heading mw-heading2"><h2 id="Proof_of_correctness">Proof of correctness</h2></div>
<p>The proof consists of two parts. First, it is proved that the algorithm produces a <a href="Spanning_tree" title="Spanning tree">spanning tree</a>. Second, it is proved that the constructed spanning tree is of minimal weight.
</p>
<div class="mw-heading mw-heading3"><h3 id="Spanning_tree">Spanning tree</h3></div>
<p>Let <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle G}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>G</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle G}</annotation>
</semantics>
</math></span><img src="./f5f3c8921a3b352de45446a6789b104458c9f90b.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.827ex; height:2.176ex;" alt="{\displaystyle G}" loading="lazy"></span> be a connected, weighted graph and let <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle Y}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>Y</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle Y}</annotation>
</semantics>
</math></span><img src="./961d67d6b454b4df2301ac571808a3538b3a6d3f.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.171ex; width:1.773ex; height:2.009ex;" alt="{\displaystyle Y}" loading="lazy"></span> be the subgraph of <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle G}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>G</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle G}</annotation>
</semantics>
</math></span><img src="./f5f3c8921a3b352de45446a6789b104458c9f90b.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.827ex; height:2.176ex;" alt="{\displaystyle G}" loading="lazy"></span> produced by the algorithm. <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle Y}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>Y</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle Y}</annotation>
</semantics>
</math></span><img src="./961d67d6b454b4df2301ac571808a3538b3a6d3f.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.171ex; width:1.773ex; height:2.009ex;" alt="{\displaystyle Y}" loading="lazy"></span> cannot have a cycle, as by definition an edge is not added if it results in a cycle. <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle Y}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>Y</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle Y}</annotation>
</semantics>
</math></span><img src="./961d67d6b454b4df2301ac571808a3538b3a6d3f.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.171ex; width:1.773ex; height:2.009ex;" alt="{\displaystyle Y}" loading="lazy"></span> cannot be disconnected, since the first encountered edge that joins two components of <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle Y}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>Y</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle Y}</annotation>
</semantics>
</math></span><img src="./961d67d6b454b4df2301ac571808a3538b3a6d3f.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.171ex; width:1.773ex; height:2.009ex;" alt="{\displaystyle Y}" loading="lazy"></span> would have been added by the algorithm. Thus, <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle Y}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>Y</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle Y}</annotation>
</semantics>
</math></span><img src="./961d67d6b454b4df2301ac571808a3538b3a6d3f.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.171ex; width:1.773ex; height:2.009ex;" alt="{\displaystyle Y}" loading="lazy"></span> is a spanning tree of <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle G}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>G</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle G}</annotation>
</semantics>
</math></span><img src="./f5f3c8921a3b352de45446a6789b104458c9f90b.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.827ex; height:2.176ex;" alt="{\displaystyle G}" loading="lazy"></span>.
</p>
<div class="mw-heading mw-heading3"><h3 id="Minimality">Minimality</h3></div>
<p>We show that the following proposition <i><b>P</b></i> is true by <a href="Mathematical_induction" title="Mathematical induction">induction</a>: If <i>F</i> is the set of edges chosen at any stage of the algorithm, then there is some minimum spanning tree that contains <i>F</i> and none of the edges rejected by the algorithm.
</p>
<ul><li>Clearly <i><b>P</b></i> is true at the beginning, when <i>F</i> is empty: any minimum spanning tree will do, and there exists one because a weighted connected graph always has a minimum spanning tree.</li>
<li>Now assume <i><b>P</b></i> is true for some non-final edge set <i>F</i> and let <i>T</i> be a minimum spanning tree that contains <i>F</i>.
<ul><li>If the next chosen edge <i>e</i> is also in <i>T</i>, then <i><b>P</b></i> is true for <i>F</i> + <i>e</i>.</li>
<li>Otherwise, if <i>e</i> is not in <i>T</i> then <i>T</i> + <i>e</i> has a cycle <i>C</i>. The cycle <i>C</i> contains edges which do not belong to <i>F</i> + <i>e</i>, since <i>e</i> does not form a cycle when added to <i>F</i> but does in <i>T</i>. Let <i>f</i> be an edge which is in <i>C</i> but not in <i>F</i> + <i>e</i>. Note that <i>f</i> also belongs to <i>T</i>, since <i>f</i> belongs to <i>T</i> + <i>e</i> but not <i>F</i> + <i>e</i>. By <i><b>P</b></i>, <i>f</i> has not been considered by the algorithm. <i>f</i> must therefore have a weight at least as large as <i>e</i>. Then <i>T</i> − <i>f</i> + <i>e</i> is a tree, and it has the same or less weight as <i>T</i>. However since <i>T</i> is a minimum spanning tree then <i>T</i> − <i>f</i> + <i>e</i> has the same weight as <i>T</i>, otherwise we get a contradiction and <i>T</i> would not be a minimum spanning tree. So <i>T</i> − <i>f</i> + <i>e</i> is a minimum spanning tree containing <i>F</i> + <i>e</i> and again <i><b>P</b></i> holds.</li></ul></li>
<li>Therefore, by the principle of induction, <i><b>P</b></i> holds when <i>F</i> has become a spanning tree, which is only possible if <i>F</i> is a minimum spanning tree itself.</li></ul>
<div class="mw-heading mw-heading2"><h2 id="Parallel_algorithm">Parallel algorithm</h2></div>
<p>Kruskal's algorithm is inherently sequential and hard to parallelize. It is, however, possible to perform the initial sorting of the edges in parallel or, alternatively, to use a parallel implementation of a <a href="Binary_heap" title="Binary heap">binary heap</a> to extract the minimum-weight edge in every iteration.<sup id="cite_ref-5" class="reference"><a href="#cite_note-5"><span class="cite-bracket">[</span>5<span class="cite-bracket">]</span></a></sup>
As parallel sorting is possible in time <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle O(n)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>O</mi>
<mo stretchy="false">(</mo>
<mi>n</mi>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle O(n)}</annotation>
</semantics>
</math></span><img src="./34109fe397fdcff370079185bfdb65826cb5565a.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:4.977ex; height:2.843ex;" alt="{\displaystyle O(n)}" loading="lazy"></span> on <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle O(\log n)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>O</mi>
<mo stretchy="false">(</mo>
<mi>log</mi>
<mo><!-- --></mo>
<mi>n</mi>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle O(\log n)}</annotation>
</semantics>
</math></span><img src="./aae0f22048ba6b7c05dbae17b056bfa16e21807d.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:8.336ex; height:2.843ex;" alt="{\displaystyle O(\log n)}" loading="lazy"></span> processors,<sup id="cite_ref-6" class="reference"><a href="#cite_note-6"><span class="cite-bracket">[</span>6<span class="cite-bracket">]</span></a></sup> the runtime of Kruskal's algorithm can be reduced to <i>O</i>(<i>E</i> α(<i>V</i>)), where α again is the inverse of the single-valued <a href="Ackermann_function" title="Ackermann function">Ackermann function</a>.
</p><p>A variant of Kruskal's algorithm, named Filter-Kruskal, has been described by Osipov et al.<sup id="cite_ref-osipov2009_7-0" class="reference"><a href="#cite_note-osipov2009-7"><span class="cite-bracket">[</span>7<span class="cite-bracket">]</span></a></sup> and is better suited for parallelization. The basic idea behind Filter-Kruskal is to partition the edges in a similar way to <a href="Quicksort" title="Quicksort">quicksort</a> and filter out edges that connect vertices of the same tree to reduce the cost of sorting. The following <a href="Pseudocode" title="Pseudocode">pseudocode</a> demonstrates this.
</p>
<pre><b>function</b> filter_kruskal(G) <b>is</b>
<b>if</b> |G.E| < kruskal_threshold:
<b>return</b> kruskal(G)
pivot = choose_random(G.E)
E<sub>≤</sub>, E<sub>></sub> = partition(G.E, pivot)
A = filter_kruskal(E<sub>≤</sub>)
E<sub>></sub> = filter(E<sub>></sub>)
A = A ∪ filter_kruskal(E<sub>></sub>)
<b>return</b> A
<b>function</b> partition(E, pivot) <b>is</b>
E<sub>≤</sub> = ∅, E<sub>></sub> = ∅
<b>foreach</b> (u, v) in E <b>do</b>
<b>if</b> weight(u, v) ≤ pivot <b>then</b>
E<sub>≤</sub> = E<sub>≤</sub> ∪ {(u, v)}
<b>else</b>
E<sub>></sub> = E<sub>></sub> ∪ {(u, v)}
<b>return</b> E<sub>≤</sub>, E<sub>></sub>
<b>function</b> filter(E) <b>is</b>
E<sub>f</sub> = ∅
<b>foreach</b> (u, v) in E <b>do</b>
<b>if</b> find_set(u) ≠ find_set(v) <b>then</b>
E<sub>f</sub> = E<sub>f</sub> ∪ {(u, v)}
<b>return</b> E<sub>f</sub>
</pre>
<p>Filter-Kruskal lends itself better to parallelization as sorting, filtering, and partitioning can easily be performed in parallel by distributing the edges between the processors.<sup id="cite_ref-osipov2009_7-1" class="reference"><a href="#cite_note-osipov2009-7"><span class="cite-bracket">[</span>7<span class="cite-bracket">]</span></a></sup>
</p><p>Finally, other variants of a parallel implementation of Kruskal's algorithm have been explored. Examples include a scheme that uses helper threads to remove edges that are definitely not part of the MST in the background,<sup id="cite_ref-8" class="reference"><a href="#cite_note-8"><span class="cite-bracket">[</span>8<span class="cite-bracket">]</span></a></sup> and a variant which runs the sequential algorithm on <i>p</i> subgraphs, then merges those subgraphs until only one, the final MST, remains.<sup id="cite_ref-9" class="reference"><a href="#cite_note-9"><span class="cite-bracket">[</span>9<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2></div>
<ul><li><a href="Prim's_algorithm" title="Prim's algorithm">Prim's algorithm</a></li>
<li><a href="Dijkstra's_algorithm" title="Dijkstra's algorithm">Dijkstra's algorithm</a></li>
<li><a href="Bor%C5%AFvka's_algorithm" title="Borůvka's algorithm">Borůvka's algorithm</a></li>
<li><a href="Reverse-delete_algorithm" title="Reverse-delete algorithm">Reverse-delete algorithm</a></li>
<li><a href="Single-linkage_clustering" title="Single-linkage clustering">Single-linkage clustering</a></li>
<li><a href="Greedy_geometric_spanner" title="Greedy geometric spanner">Greedy geometric spanner</a></li></ul>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1239543626">
/* start https://en.wikipedia.org/ */
.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}
/* end https://en.wikipedia.org/ */
</style><div class="reflist">
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-1"><span class="mw-cite-backlink"><b><a href="#cite_ref-1">^</a></b></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */
.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}
/* end https://en.wikipedia.org/ */
</style><cite id="CITEREFKleinberg2006" class="citation book cs1">Kleinberg, Jon (2006). <i>Algorithm design</i>. Éva Tardos. Boston: Pearson/Addison-Wesley. pp. <span class="nowrap">142–</span>151. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>0-321-29535-8</bdi>. <a href="OCLC_(identifier)" class="mw-redirect" title="OCLC (identifier)">OCLC</a> <a rel="nofollow" class="external text" href="https://search.worldcat.org/oclc/57422612">57422612</a>.</cite></span>
</li>
<li id="cite_note-:0-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-:0_2-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFCormenCharles_E_Leiserson,_Ronald_L_Rivest,_Clifford_Stein2009" class="citation book cs1">Cormen, Thomas; Charles E Leiserson, Ronald L Rivest, Clifford Stein (2009). <span class="id-lock-limited" title="Free access subject to limited trial, subscription normally required"><a rel="nofollow" class="external text" href="https://archive.org/details/introductiontoal00corm_805"><i>Introduction To Algorithms</i></a></span> (Third ed.). MIT Press. pp. <a rel="nofollow" class="external text" href="https://archive.org/details/introductiontoal00corm_805/page/n651">631</a>. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>978-0262258104</bdi>.</cite><span class="cs1-maint citation-comment"><code class="cs1-code">{{cite book}}</code>: CS1 maint: multiple names: authors list (link)</span></span>
</li>
<li id="cite_note-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-3">^</a></b></span> <span class="reference-text"><cite id="CITEREFKruskal1956" class="citation journal cs1"><a href="Joseph_Kruskal" title="Joseph Kruskal">Kruskal, J. B.</a> (1956). <a rel="nofollow" class="external text" href="https://doi.org/10.1090%2FS0002-9939-1956-0078686-7">"On the shortest spanning subtree of a graph and the traveling salesman problem"</a>. <i><a href="Proceedings_of_the_American_Mathematical_Society" title="Proceedings of the American Mathematical Society">Proceedings of the American Mathematical Society</a></i>. <b>7</b> (1): <span class="nowrap">48–</span>50. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1090%2FS0002-9939-1956-0078686-7">10.1090/S0002-9939-1956-0078686-7</a></span>. <a href="JSTOR_(identifier)" class="mw-redirect" title="JSTOR (identifier)">JSTOR</a> <a rel="nofollow" class="external text" href="https://www.jstor.org/stable/2033241">2033241</a>.</cite></span>
</li>
<li id="cite_note-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-4">^</a></b></span> <span class="reference-text"><cite id="CITEREFLobermanWeinberger1957" class="citation journal cs1">Loberman, H.; Weinberger, A. (October 1957). <a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F320893.320896">"Formal Procedures for connecting terminals with a minimum total wire length"</a>. <i>Journal of the ACM</i>. <b>4</b> (4): <span class="nowrap">428–</span>437. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F320893.320896">10.1145/320893.320896</a></span>. <a href="S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a> <a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:7320964">7320964</a>.</cite></span>
</li>
<li id="cite_note-5"><span class="mw-cite-backlink"><b><a href="#cite_ref-5">^</a></b></span> <span class="reference-text"><cite id="CITEREFQuinnDeo1984" class="citation journal cs1">Quinn, Michael J.; Deo, Narsingh (1984). <a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F2514.2515">"Parallel graph algorithms"</a>. <i>ACM Computing Surveys</i>. <b>16</b> (3): <span class="nowrap">319–</span>348. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F2514.2515">10.1145/2514.2515</a></span>. <a href="S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a> <a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:6833839">6833839</a>.</cite></span>
</li>
<li id="cite_note-6"><span class="mw-cite-backlink"><b><a href="#cite_ref-6">^</a></b></span> <span class="reference-text"><cite id="CITEREFGramaGuptaKarypisKumar2003" class="citation book cs1">Grama, Ananth; Gupta, Anshul; Karypis, George; Kumar, Vipin (2003). <i>Introduction to Parallel Computing</i>. Addison-Wesley. pp. <span class="nowrap">412–</span>413. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>978-0201648652</bdi>.</cite></span>
</li>
<li id="cite_note-osipov2009-7"><span class="mw-cite-backlink">^ <a href="#cite_ref-osipov2009_7-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-osipov2009_7-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><cite id="CITEREFOsipovSandersSingler2009" class="citation journal cs1">Osipov, Vitaly; Sanders, Peter; Singler, Johannes (2009). <a rel="nofollow" class="external text" href="https://doi.org/10.1137%2F1.9781611972894.5">"The filter-kruskal minimum spanning tree algorithm"</a>. <i>Proceedings of the Eleventh Workshop on Algorithm Engineering and Experiments (ALENEX). Society for Industrial and Applied Mathematics</i>: <span class="nowrap">52–</span>61. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1137%2F1.9781611972894.5">10.1137/1.9781611972894.5</a></span>. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>978-0-89871-930-7</bdi>.</cite></span>
</li>
<li id="cite_note-8"><span class="mw-cite-backlink"><b><a href="#cite_ref-8">^</a></b></span> <span class="reference-text"><cite id="CITEREFKatsigiannisAnastopoulosKonstantinosKoziris2012" class="citation book cs1">Katsigiannis, Anastasios; Anastopoulos, Nikos; Konstantinos, Nikas; Koziris, Nectarios (2012). "An Approach to Parallelize Kruskal's Algorithm Using Helper Threads". <a rel="nofollow" class="external text" href="http://tarjomefa.com/wp-content/uploads/2017/10/7793-English-TarjomeFa.pdf"><i>2012 IEEE 26th International Parallel and Distributed Processing Symposium Workshops & PhD Forum</i></a> <span class="cs1-format">(PDF)</span>. pp. <span class="nowrap">1601–</span>1610. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1109%2FIPDPSW.2012.201">10.1109/IPDPSW.2012.201</a>. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>978-1-4673-0974-5</bdi>. <a href="S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a> <a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:14430930">14430930</a>.</cite></span>
</li>
<li id="cite_note-9"><span class="mw-cite-backlink"><b><a href="#cite_ref-9">^</a></b></span> <span class="reference-text"><cite id="CITEREFLončarŠkrbićBalaž2014" class="citation book cs1">Lončar, Vladimir; Škrbić, Srdjan; Balaž, Antun (2014). <a rel="nofollow" class="external text" href="https://www.researchgate.net/publication/235994104">"Parallelization of Minimum Spanning Tree Algorithms Using Distributed Memory Architectures"</a>. <i>Transactions on Engineering Technologies</i>. pp. <span class="nowrap">543–</span>554. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1007%2F978-94-017-8832-8_39">10.1007/978-94-017-8832-8_39</a>. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>978-94-017-8831-1</bdi>.</cite></span>
</li>
</ol></div></div>
<ul><li><a href="Thomas_H._Cormen" title="Thomas H. Cormen">Thomas H. Cormen</a>, <a href="Charles_E._Leiserson" title="Charles E. Leiserson">Charles E. Leiserson</a>, <a href="Ronald_L._Rivest" class="mw-redirect" title="Ronald L. Rivest">Ronald L. Rivest</a>, and <a href="Clifford_Stein" title="Clifford Stein">Clifford Stein</a>. <i><a href="Introduction_to_Algorithms" title="Introduction to Algorithms">Introduction to Algorithms</a></i>, Second Edition. MIT Press and McGraw-Hill, 2001. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>0-262-03293-7</bdi>. Section 23.2: The algorithms of Kruskal and Prim, pp. 567–574.</li>
<li><a href="Michael_T._Goodrich" title="Michael T. Goodrich">Michael T. Goodrich</a> and <a href="Roberto_Tamassia" title="Roberto Tamassia">Roberto Tamassia</a>. <i>Data Structures and Algorithms in Java</i>, Fourth Edition. John Wiley & Sons, Inc., 2006. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>0-471-73884-0</bdi>. Section 13.7.1: Kruskal's Algorithm, pp. 632..</li></ul>
<div class="mw-heading mw-heading2"><h2 id="External_links">External links</h2></div>
<ul><li><a rel="nofollow" class="external text" href="https://github.com/carlschroedl/kruskals-minimum-spanning-tree-algorithm-example-data">Data for the article's example</a>.</li>
<li><a rel="nofollow" class="external text" href="https://gephi.org/plugins/#/plugin/spanning-tree-plugin">Gephi Plugin For Calculating a Minimum Spanning Tree</a> <a rel="nofollow" class="external text" href="https://github.com/carlschroedl/gephi-plugins/tree/minimum-spanning-tree-plugin/modules/MinimumSpanningTree">source code</a>.</li>
<li><a rel="nofollow" class="external text" href="http://www.geeksforgeeks.org/kruskals-minimum-spanning-tree-using-stl-in-c/">Kruskal's Algorithm with example and program in c++</a></li>
<li><a rel="nofollow" class="external text" href="https://meyavuz.wordpress.com/2017/03/11/how-does-kruskals-algorithm-progress/">Kruskal's Algorithm code in C++ as applied to random numbers</a></li>
<li><a rel="nofollow" class="external text" href="https://gist.github.com/DanilAndreev/e519d77eff91f03f09616c9170db7941">Kruskal's Algorithm code in Python with explanation</a></li></ul>
<div class="navbox-styles"><style data-mw-deduplicate="TemplateStyles:r1129693374">
/* start https://en.wikipedia.org/ */
.mw-parser-output .hlist dl,.mw-parser-output .hlist ol,.mw-parser-output .hlist ul{margin:0;padding:0}.mw-parser-output .hlist dd,.mw-parser-output .hlist dt,.mw-parser-output .hlist li{margin:0;display:inline}.mw-parser-output .hlist.inline,.mw-parser-output .hlist.inline dl,.mw-parser-output .hlist.inline ol,.mw-parser-output .hlist.inline ul,.mw-parser-output .hlist dl dl,.mw-parser-output .hlist dl ol,.mw-parser-output .hlist dl ul,.mw-parser-output .hlist ol dl,.mw-parser-output .hlist ol ol,.mw-parser-output .hlist ol ul,.mw-parser-output .hlist ul dl,.mw-parser-output .hlist ul ol,.mw-parser-output .hlist ul ul{display:inline}.mw-parser-output .hlist .mw-empty-li{display:none}.mw-parser-output .hlist dt::after{content:": "}.mw-parser-output .hlist dd::after,.mw-parser-output .hlist li::after{content:" · ";font-weight:bold}.mw-parser-output .hlist dd:last-child::after,.mw-parser-output .hlist dt:last-child::after,.mw-parser-output .hlist li:last-child::after{content:none}.mw-parser-output .hlist dd dd:first-child::before,.mw-parser-output .hlist dd dt:first-child::before,.mw-parser-output .hlist dd li:first-child::before,.mw-parser-output .hlist dt dd:first-child::before,.mw-parser-output .hlist dt dt:first-child::before,.mw-parser-output .hlist dt li:first-child::before,.mw-parser-output .hlist li dd:first-child::before,.mw-parser-output .hlist li dt:first-child::before,.mw-parser-output .hlist li li:first-child::before{content:" (";font-weight:normal}.mw-parser-output .hlist dd dd:last-child::after,.mw-parser-output .hlist dd dt:last-child::after,.mw-parser-output .hlist dd li:last-child::after,.mw-parser-output .hlist dt dd:last-child::after,.mw-parser-output .hlist dt dt:last-child::after,.mw-parser-output .hlist dt li:last-child::after,.mw-parser-output .hlist li dd:last-child::after,.mw-parser-output .hlist li dt:last-child::after,.mw-parser-output .hlist li li:last-child::after{content:")";font-weight:normal}.mw-parser-output .hlist ol{counter-reset:listitem}.mw-parser-output .hlist ol>li{counter-increment:listitem}.mw-parser-output .hlist ol>li::before{content:" "counter(listitem)"\a0 "}.mw-parser-output .hlist dd ol>li:first-child::before,.mw-parser-output .hlist dt ol>li:first-child::before,.mw-parser-output .hlist li ol>li:first-child::before{content:" ("counter(listitem)"\a0 "}
/* end https://en.wikipedia.org/ */
</style><style data-mw-deduplicate="TemplateStyles:r1236075235">
/* start https://en.wikipedia.org/ */
.mw-parser-output .navbox{box-sizing:border-box;border:1px solid #a2a9b1;width:100%;clear:both;font-size:88%;text-align:center;padding:1px;margin:1em auto 0}.mw-parser-output .navbox .navbox{margin-top:0}.mw-parser-output .navbox+.navbox,.mw-parser-output .navbox+.navbox-styles+.navbox{margin-top:-1px}.mw-parser-output .navbox-inner,.mw-parser-output .navbox-subgroup{width:100%}.mw-parser-output .navbox-group,.mw-parser-output .navbox-title,.mw-parser-output .navbox-abovebelow{padding:0.25em 1em;line-height:1.5em;text-align:center}.mw-parser-output .navbox-group{white-space:nowrap;text-align:right}.mw-parser-output .navbox,.mw-parser-output .navbox-subgroup{background-color:#fdfdfd}.mw-parser-output .navbox-list{line-height:1.5em;border-color:#fdfdfd}.mw-parser-output .navbox-list-with-group{text-align:left;border-left-width:2px;border-left-style:solid}.mw-parser-output tr+tr>.navbox-abovebelow,.mw-parser-output tr+tr>.navbox-group,.mw-parser-output tr+tr>.navbox-image,.mw-parser-output tr+tr>.navbox-list{border-top:2px solid #fdfdfd}.mw-parser-output .navbox-title{background-color:#ccf}.mw-parser-output .navbox-abovebelow,.mw-parser-output .navbox-group,.mw-parser-output .navbox-subgroup .navbox-title{background-color:#ddf}.mw-parser-output .navbox-subgroup .navbox-group,.mw-parser-output .navbox-subgroup .navbox-abovebelow{background-color:#e6e6ff}.mw-parser-output .navbox-even{background-color:#f7f7f7}.mw-parser-output .navbox-odd{background-color:transparent}.mw-parser-output .navbox .hlist td dl,.mw-parser-output .navbox .hlist td ol,.mw-parser-output .navbox .hlist td ul,.mw-parser-output .navbox td.hlist dl,.mw-parser-output .navbox td.hlist ol,.mw-parser-output .navbox td.hlist ul{padding:0.125em 0}.mw-parser-output .navbox .navbar{display:block;font-size:100%}.mw-parser-output .navbox-title .navbar{float:left;text-align:left;margin-right:0.5em}body.skin--responsive .mw-parser-output .navbox-image img{max-width:none!important}@media print{body.ns-0 .mw-parser-output .navbox{display:none!important}}
/* end https://en.wikipedia.org/ */
</style></div><div role="navigation" class="navbox" aria-labelledby="Graph_and_tree_traversal_algorithms231" style="padding:3px"><table class="nowraplinks mw-collapsible autocollapse navbox-inner" style="border-spacing:0;background:transparent;color:inherit"><tbody><tr><th scope="col" class="navbox-title" colspan="2"><style data-mw-deduplicate="TemplateStyles:r1239400231">
/* start https://en.wikipedia.org/ */
.mw-parser-output .navbar{display:inline;font-size:88%;font-weight:normal}.mw-parser-output .navbar-collapse{float:left;text-align:left}.mw-parser-output .navbar-boxtext{word-spacing:0}.mw-parser-output .navbar ul{display:inline-block;white-space:nowrap;line-height:inherit}.mw-parser-output .navbar-brackets::before{margin-right:-0.125em;content:"[ "}.mw-parser-output .navbar-brackets::after{margin-left:-0.125em;content:" ]"}.mw-parser-output .navbar li{word-spacing:-0.125em}.mw-parser-output .navbar a>span,.mw-parser-output .navbar a>abbr{text-decoration:inherit}.mw-parser-output .navbar-mini abbr{font-variant:small-caps;border-bottom:none;text-decoration:none;cursor:inherit}.mw-parser-output .navbar-ct-full{font-size:114%;margin:0 7em}.mw-parser-output .navbar-ct-mini{font-size:114%;margin:0 4em}html.skin-theme-clientpref-night .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}@media(prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}}@media print{.mw-parser-output .navbar{display:none!important}}
/* end https://en.wikipedia.org/ */
</style><div id="Graph_and_tree_traversal_algorithms231" style="font-size:114%;margin:0 4em"><a href="Graph_traversal" title="Graph traversal">Graph</a> and <a href="Tree_traversal" title="Tree traversal">tree</a> traversal algorithms</div></th></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Graph_traversal" title="Graph traversal">Search</a></th><td class="navbox-list-with-group navbox-list navbox-odd hlist" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Alpha%E2%80%93beta_pruning" title="Alpha–beta pruning">α–β pruning</a></li>
<li><a href="A*_search_algorithm" title="A* search algorithm"><b>A*</b></a>
<ul><li><a href="Iterative_deepening_A*" title="Iterative deepening A*">IDA*</a></li>
<li><a href="Lifelong_Planning_A*" title="Lifelong Planning A*">LPA*</a></li>
<li><a href="SMA*" title="SMA*">SMA*</a></li></ul></li>
<li><a href="Best-first_search" title="Best-first search">Best-first search</a></li>
<li><a href="Beam_search" title="Beam search">Beam search</a></li>
<li><a href="Bidirectional_search" title="Bidirectional search">Bidirectional search</a></li>
<li><a href="Breadth-first_search" title="Breadth-first search">Breadth-first search</a>
<ul><li><a href="Lexicographic_breadth-first_search" title="Lexicographic breadth-first search">Lexicographic</a></li>
<li><a href="Parallel_breadth-first_search" title="Parallel breadth-first search">Parallel</a></li></ul></li>
<li><a href="B*" title="B*">B*</a></li>
<li><a href="Depth-first_search" title="Depth-first search">Depth-first search</a>
<ul><li><a href="Iterative_deepening_depth-first_search" title="Iterative deepening depth-first search">Iterative deepening</a></li></ul></li>
<li><a href="D*" title="D*">D*</a></li>
<li><a href="Fringe_search" title="Fringe search">Fringe search</a></li>
<li><a href="Jump_point_search" title="Jump point search">Jump point search</a></li>
<li><a href="Monte_Carlo_tree_search" title="Monte Carlo tree search">Monte Carlo tree search</a></li>
<li><a href="SSS*" title="SSS*">SSS*</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Shortest_path_problem" title="Shortest path problem">Shortest path</a></th><td class="navbox-list-with-group navbox-list navbox-even hlist" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Bellman%E2%80%93Ford_algorithm" title="Bellman–Ford algorithm">Bellman–Ford</a></li>
<li><a href="Dijkstra's_algorithm" title="Dijkstra's algorithm">Dijkstra's</a></li>
<li><a href="Floyd%E2%80%93Warshall_algorithm" title="Floyd–Warshall algorithm">Floyd–Warshall</a></li>
<li><a href="Johnson's_algorithm" title="Johnson's algorithm">Johnson's</a></li>
<li><a href="Shortest_path_faster_algorithm" class="mw-redirect" title="Shortest path faster algorithm">Shortest path faster</a></li>
<li><a href="Yen's_algorithm" title="Yen's algorithm">Yen's</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Minimum_spanning_tree" title="Minimum spanning tree">Minimum spanning tree</a></th><td class="navbox-list-with-group navbox-list navbox-odd hlist" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Bor%C5%AFvka's_algorithm" title="Borůvka's algorithm">Borůvka's</a></li>
<li><a href="Prim's_algorithm" title="Prim's algorithm">Prim's</a></li>
<li><a href="Reverse-delete_algorithm" title="Reverse-delete algorithm">Reverse-delete</a></li></ul>
</div></td></tr><tr><td class="navbox-abovebelow" colspan="2"><div><a href="List_of_algorithms#Graph_search" title="List of algorithms">List of graph search algorithms</a></div></td></tr></tbody></table></div></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2025-07-18" href="https://en.wikipedia.org/wiki/?title=Kruskal's_algorithm&oldid=1301101352">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>
</body></html>